;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Report.LocationSummary", [])
        .controller("LocationSummaryCtrl", ["$scope", "$state", "ybWidget", "ybHttp", "MESG_TYPE", "$filter", "$timeout", "UserContextService", "$stateParams", function ($scope, $state, ybWidget, ybHttp, MESG_TYPE, $filter, $timeout, UserContextService, $stateParams) {
            $scope.activeFlag = [true];

            $scope.pageInfo = {
                totalPages: 1,
                totalRows: 0,
                pageSize: 10,
                curPage: 1
            };

            $scope.exportParam = {
                url: ybHttp.RequestUrl("device", "/locationReport/export"),
            };

            $scope.toolbarConfig = {
                showAgentAdSearch: false,
            };

            $scope.switchToolbar = function (toolbar) {
                if (!!$scope.toolbarConfig[toolbar]) {
                    $scope.toolbarConfig[toolbar] = false;
                } else {
                    $timeout(function () {
                        $scope.toolbarConfig[toolbar] = true;
                    });
                }
            };

            $scope.condition = {
                priceType:1
            }; // 搜索条件
            $scope.dataList = []; // 数据列表
            $scope.sumRowData = []; // 总计的数据

            // 重置搜索条件
            $scope.reset = function () {
                $scope.condition = {
                    priceType:1
                };
            };

            $scope.checkDate = function (obj, startFiled, endFiled) {
                var timeFormatObj = ybWidget.CheckDate(obj[startFiled], obj[endFiled]);
                if (!!timeFormatObj.tStart) {
                    obj[startFiled] = timeFormatObj.tStart;
                }
                if (!!timeFormatObj.tEnd) {
                    obj[endFiled] = timeFormatObj.tEnd;
                }
            };

            // 搜索供货关系列表
            $scope.search = function (curPage) {
                getDataList(curPage);
            };

            // 获取代理商满意度列表
            function getDataList(curPage) {
                if (!!curPage) {
                    $scope.pageInfo.curPage = curPage;
                }

                //遍历搜索条件对象里的空值并删除  不然搜索不出数据
                Object.keys($scope.condition).forEach(function (key) {
                    if (!$scope.condition[key] && $scope.condition[key] !== 0) delete $scope.condition[key];
                });

                var reqUrl = "/locationReport/pageList";
                var param = {
                    pageNum: $scope.pageInfo.curPage,
                    pageSize: $scope.pageInfo.pageSize,
                    filters: angular.copy($scope.condition)
                };
                ybHttp.Post('device', reqUrl, param).then(function (res) {
                    if (res.code !== 0) {
                        ybWidget.ShowMessage(res, MESG_TYPE.Error);
                        return;
                    }
                    $scope.sumRowData = res.value.list.pop(); // 取出最后一条（并删除）
                    $scope.pageInfo.totalRows = res.value.total;
                    $scope.pageInfo.totalPages = res.value.pages;
                    $scope.dataList = res.value.list;
                });
            }

            // 按钮权限code
            var btnPermissionCode = {
                xxxxx: window.ActionCode.xxxx
            };

            // 按钮权限
            $scope.btnPermission = {
                xxxxx: true
            };

            function setBtnPermission() {
                for (var key in btnPermissionCode) {
                    $scope.btnPermission[key] = UserContextService.CheckPermission([btnPermissionCode[key]]);
                }
            }

            (function () {
                UserContextService.SetBtnPermission(setBtnPermission);
            })();
        }])
    ;
})(window, window.angular);
